package com.zhitong.money.mapper;

import com.zhitong.money.entity.MsgEmp;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * @Author: Andy Zhang
 * @Description:
 * @Date: 11:03 2021/3/5
 * @Company: wisecard
 */
@Mapper
public interface MsgEmpMapper {
    @Results(id = "msgEmpMap", value = {
            @Result(column = "mid" ,property = "mid"),
            @Result(column = "tid",property = "tid"),
            @Result(column = "name",property = "name"),
            @Result(column = "status",property = "status"),
            @Result(column = "title",property = "title"),
            @Result(column = "enable",property = "enable"),
            @Result(column = "createTime",property = "createTime"),
    })
    @Select("select message_employee.*,employee.name from employee,message_employee where tid = tellerId")
    public List<MsgEmp> findRelatedByMid(String mid);

    @Select("select message_employee.*,message.title,message.createTime from message,message_employee where mid=id and message_employee.tid=#{tid} and enable='01'")
    public List<MsgEmp> findRelatedByTid(String tid);

    @Insert("insert into message_employee values(#{mid},#{tid},'01','00')")
    public void addRelated(String mid,String tid);

    @Delete("delete from message_employee where mid=#{mid} and tid=#{tid}")
    public void delRelated(String mid,String tid);

    @Delete("delete  from message_employee where mid = #{mid}")
    public void delByMid(String mid);

    @Delete({
            "<script>",
            "delete from message_employee",
            "where mid in ",
            "<foreach item='item' collection='mids' separator=',' open='(' close=')'>",
            "#{item}",
            "</foreach>",
            "</script>"
    })
    public void delByMids(List<String> mids);


    @Delete({
            "<script>",
            "delete from message_employee",
            "where mid=#{mid} and tid in ",
            "<foreach item='item' collection='tids' separator=',' open='(' close=')'>",
            "#{item}",
            "</foreach>",
            "</script>"
    })
    public void delRelateds(String mid,List<String> tids);

    @Update("update message_employee set enable = #{enable} where mid=#{mid} and tid=#{tid}")
    public void updateEnable(String mid,String tid,String enable);

    @Update("update message_employee set status = #{status} where mid=#{mid} and tid=#{tid}")
    public void updateRelatedStatus(String mid,String tid,String status);
}
